<?php

namespace AppBundle\Controller\Admin;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Request;
use AppBundle\Entity\Users;

class LoginController extends Controller
{
    /**
     * login page
     *
     */
    public function indexAction(Request $request)
    {
        // $repository = $this->getDoctrine()->getRepository('AppBundle:Users');
        // $user = $repository->findOneById(3);
        // dump( $user);die;
        // $user = new Users('admin','');
        // $plainPassword = '123456';
        // $encoder = $this->get('security.password_encoder');
        // $encoded = $encoder->encodePassword($user,$plainPassword);
        // $user->setPassword($encoded);
        // $em = $this->getDoctrine()->getManager();
        // $em->persist($user);
        // $em->flush();
        // dump($user->getId());die;
        $authenticationUtils = $this->get('security.authentication_utils');

        // get the login error if there is one
        $error = $authenticationUtils->getLastAuthenticationError();

        // last username entered by the user
        $lastUsername = $authenticationUtils->getLastUsername();

        # render login page
        return $this->render('admin/login/index.html.twig',
            array(
                // last username entered by the user
                'last_username' => $lastUsername,
                'error' => $error,
            )
        );
    }

    /**
     * user auth
     */
    public function authAction(Request $request)
    {

        dump($request->all());die;
    }
}
